package com.stm.bi.web;

import com.stm.bi.dto.cmd.ReportModelAdd;
import com.stm.bi.dto.query.ReportModelPageQry;
import com.stm.bi.dto.vo.ReportModelVO;
import com.stm.bi.model.DatatablePage;
import com.stm.bi.service.ReportModelService;
import com.stm.framework.annotation.Module;
import com.stm.framework.annotation.ReqParam;
import com.stm.framework.annotation.RestApi;
import com.stm.framework.dto.Response;
import com.stm.framework.model.CustomizePage;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;


/**
* 报表模型-controller服务
*
* @author zhouyuanpeng
* @date 2025-05-22
*/
@RestController
@RequestMapping("/reportModel")
@Module("报表模型")
public class ReportModelController {
    @Resource
    private ReportModelService reportModelService;


    /**
    * 报表模型分页查询
    */
    @GetMapping(value = "/selectPage")
    @RestApi(name = "报表模型分页查询", author = "zhouyuanpeng", idx=1)
    public Response<CustomizePage<ReportModelVO>> selectPage(ReportModelPageQry reportModelPageQry) {
        return reportModelService.selectPage(reportModelPageQry);
    }

    /**
    * 报表模型详细查询
    */
    @GetMapping(value = "/{id}")
    @RestApi(name = "报表模型详细查询", author = "zhouyuanpeng", idx=2)
    public Response<ReportModelVO> selectById(@PathVariable("id") @ReqParam(label = "id",required = true) Long id) {
        return reportModelService.selectById(id);
    }

    /**
    * 报表模型新增
    */
    @PostMapping(value = "/createOrUpdate")
    @RestApi(name = "新增或修改报表模型", author = "zhouyuanpeng", idx=3)
    public Response<ReportModelAdd> createOrUpdate(@RequestBody ReportModelAdd reportModelAdd) {
        return reportModelService.createOrUpdate(reportModelAdd);
    }


    @PostMapping(value = "/reportPreview")
    @RestApi(name = "报表模型预览", author = "zp", idx=5)
    public Response<DatatablePage> reportPreview(@RequestBody ReportModelAdd reportModelAdd) {
        return reportModelService.reportPreview(reportModelAdd);
    }

    @GetMapping(value = "/selectRandomTable")
    @RestApi(name = "随机数表格", author = "zp", idx=6)
    public Response<DatatablePage> selectRandomTable(
            @RequestParam("modelId") @ReqParam(label = "模版ID",required = true) Long modelId,
            @RequestParam("standardId") @ReqParam(label = "水准ID",required = true) Long standardId,
            @RequestParam("showData") @ReqParam(label = "是否展示数据",required = true) Boolean showData) {
        return reportModelService.selectRandomTable(modelId, standardId, showData);
    }
}
